package com.magicalcoder.youyaboot.admin.api.syshuahen;

import com.magicalcoder.youyaboot.core.service.CommonRestController;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.math.*;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import com.magicalcoder.youyaboot.core.common.constant.PageConstant;
import com.magicalcoder.youyaboot.core.common.exception.BusinessException;
import com.magicalcoder.youyaboot.core.serialize.ResponseMsg;
import com.magicalcoder.youyaboot.model.SysHuahen;
import com.magicalcoder.youyaboot.service.syshuahen.service.SysHuahenService;

import com.magicalcoder.youyaboot.core.utils.ListUtil;
import com.magicalcoder.youyaboot.core.utils.MapUtil;
import com.magicalcoder.youyaboot.core.utils.StringUtil;


/**
* 代码为自动生成 Created by www.magicalcoder.com
* 软件作者：何栋宇 qq:709876443
* 如果你改变了此类 read 请将此行删除
* 欢迎加入官方QQ群:648595928
*/

@RequestMapping("/admin/sys_huahen_rest/")
@RestController
public class AdminSysHuahenRestController extends CommonRestController<SysHuahen,Integer> implements InitializingBean
{

    @Resource
    private SysHuahenService sysHuahenService;

        //分页查询
    @RequestMapping(value={"page"}, method={RequestMethod.GET})
    public ResponseMsg page(
        @RequestParam(required = false,value ="vehicletypeFirst")                            String vehicletypeFirst ,
        @RequestParam(required = false,value ="licensePlateNumberFirst")                            String licensePlateNumberFirst ,
        @RequestParam(required = false,value ="propertiesFirst")                            String propertiesFirst ,
        @RequestParam(required = false,value ="huahenweightFirst")                            Integer huahenweightFirst ,
        @RequestParam(required = false,value ="basicpremiumFirst")                            BigDecimal basicpremiumFirst ,
        @RequestParam(required = false,value ="thecartimeFirst")                            Integer thecartimeFirst ,
        @RequestParam int page,@RequestParam int limit,@RequestParam(required = false) String safeOrderBy
        ,HttpServletResponse response,@RequestParam(required = false) Integer queryType
    ){
        Map<String,Object> query = new HashMap();
        query.put("vehicletypeFirst",coverBlankToNull(vehicletypeFirst));
        query.put("licensePlateNumberFirst",coverBlankToNull(licensePlateNumberFirst));
        query.put("propertiesFirst",coverBlankToNull(propertiesFirst));
        query.put("huahenweightFirst",huahenweightFirst);
        query.put("basicpremiumFirst",basicpremiumFirst);
        query.put("thecartimeFirst",thecartimeFirst);
        Integer count = sysHuahenService.getModelListCount(query);
        if(StringUtil.isBlank(safeOrderBy)){
            query.put("notSafeOrderBy","id asc");
        }else{
            query.put("safeOrderBy",safeOrderBy);
        }
        if(queryType==null || queryType == QUERY_TYPE_SEARCH){//普通查询
            limit = Math.min(limit, PageConstant.MAX_LIMIT);
            query.put("start",(page - 1) * limit);query.put("limit",limit);
            return new ResponseMsg(count,sysHuahenService.getModelList(query));
        }else if(queryType == QUERY_TYPE_EXPORT_EXCEL){
            query.put("start",(page - 1) * limit);query.put("limit",limit);
            exportExcel(response,sysHuahenService.getModelList(query),"划痕险费率表;",
            new String[]{"id","车辆类型","车牌号","使用性质","划痕轻重","座位1","座位2","吨位1","吨位2","基础保费","车龄","汽车5座","6座以下","汽车7座","汽车8座","大巴18-22座","大巴33座","货车","大巴45座","创建人","创建时间","修改人","修改时间","是否删除","费率分类"},
            new String[]{"","","","","","","","","","","","","","","","","","","","","","","","",""});
        }
        return null;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        super.commonService = sysHuahenService;
        super.primaryKey = "id";//硬编码此实体的主键名称
    }
}
